<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/9/13
 * Time: 19:36
 */

namespace Service\DownloadMusic\DownWeb;

use Curl\Curl;

class CtFile implements DownInterface
{
	public $file;
	public $id;
	public $url;
	public $fileChk;
	public $curl;
	public $downUrl;
	public $fileName;
	public $fileSize;

	public function __construct($url)
	{
		$this->curl = new Curl();
		$this->url = $url;
		$this->setId();
	}
	
	
	public function setId(){
		$url = str_replace('https://','',$this->url);
		$this->id =  explode('/',$url)[2];
		$this->setFileChk();
	}


	public function setFileChk(){
		$data = $this->curl->post("https://webapi.400gb.com/getfile.php?f={$this->id}");
		$this->fileChk  = json_decode($data,1)['file_chk'];
		$this->fileName = json_decode($data,1)['file_name'];
		$this->fileSize = json_decode($data,1)['file_size'];
		$this->setDownUrl();

	}
	public function setDownUrl(){
		$uid = explode('-',$this->id)[0];
		$fid = explode('-',$this->id)[1];

		$data = $this->curl->post("https://webapi.400gb.com/get_file_url.php?uid={$uid}&fid={$fid}&folder_id=0&file_chk={$this->fileChk}");
		$this->downUrl = json_decode($data,1)['downurl'];

	}
	public function getDownUrl(){
		return $this->downUrl;
	}
	
	public function getFileChk(){
		return $this->fileChk;
	}
	
	public function getId(){
		return $this->id;
	}
	public function getFileName(){
		return $this->fileName;
	}
	public function getFileSize(){
		return $this->fileSize;
	}
}